import 'package:intl/intl.dart';

class TimeUtils {
  static String minsToHHMM(int mins) {
    return '${(mins ~/ 60).toString().padLeft(2, '0')}:${(mins % 60).toString().padLeft(2, '0')}';
  }

  static DateTime getTodayZeroTime() {
    int year = DateTime.now().year;
    int month = DateTime.now().month;
    int day = DateTime.now().day;
    DateTime todayZeroTime = DateTime(year, month, day, 0, 0, 0);
    return todayZeroTime;
  }

  static DateTime getZeroTime(DateTime date) {
    int year = date.year;
    int month = date.month;
    int day = date.day;
    DateTime todayZeroTime = DateTime(year, month, day, 0, 0, 0);
    return todayZeroTime;
  }

  static String formatHHMM(int timeMills) {
    DateFormat fmt = DateFormat("HH:mm");
    return fmt.format(DateTime.fromMillisecondsSinceEpoch(timeMills));
  }

  static String formatHHMMFromSecond(int second) {
    return '${(second ~/ 60).toString().padLeft(2, '0')}:${(second % 60).toString().padLeft(2, '0')}';
  }

  static String formatMMFromSecond(int second) {
    return '${(second ~/ 60)}';
  }

  static String formatMMDDHHMM(int timeMills) {
    DateFormat fmt = DateFormat("MM月dd日 HH:mm");
    return fmt.format(DateTime.fromMillisecondsSinceEpoch(timeMills));
  }

  static String formatYYMMDDHHMM(int timeMills) {
    DateFormat fmt = DateFormat("yyyy年MM月dd日 HH:mm");
    return fmt.format(DateTime.fromMillisecondsSinceEpoch(timeMills));
  }

  static String formatYYMMDD(int timeMills) {
    DateFormat fmt = DateFormat("yyyy年MM月dd日");
    return fmt.format(DateTime.fromMillisecondsSinceEpoch(timeMills));
  }

  static String buildTimeRangeHM(int mins) {
    NumberFormat formatter = NumberFormat("00");
    return '${formatter.format(mins ~/ 60)}时${formatter.format(mins % 60)}分';
  }
}
